<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link href="/static/css/bootstrap.css" rel="stylesheet">
    <script type="text/javascript" src="/static/js/jquery-3.2.1.js"></script>
</head>
<body>
<center>
    <form action="/list" method="post">
        生日:<input type="text" name="date1" value="<fmt:formatDate value='${userVo.date1}' pattern='yyyy-MM-dd'/> ">--
        <input type="text" name="date2" value="<fmt:formatDate value='${userVo.date2}' pattern='yyyy-MM-dd'/>">
        <button>查询</button>
    </form>
<table class="table">
    <tr>
        <td><input type="checkbox" onclick="chAll()"></td>
        <td>ID</td>
        <td>性别</td>
        <td>手机号</td>
        <td>生日</td>
        <td>用户名</td>
        <td>密码</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${pg.list}" var="user">
        <tr>
            <td><input type="checkbox" value="${user.id}" name="ch"></td>
            <td>${user.id}</td>
            <td>${user.sex}</td>
            <td>${user.telephone}</td>
            <td><fmt:formatDate value="${user.birthday}" pattern="yyyy-MM-dd"></fmt:formatDate> </td>
            <td>${user.username}</td>
            <td>${user.password}</td>
            <td><a href="/getUser?id=${user.id}">修改</a></td>
        </tr>
    </c:forEach>
</table>
    <input type="button" value="批量删除" onclick="delAll()">
    <jsp:include page="/static/common/pages.jsp"></jsp:include>

</center>
<script>
    function chAll() {
        $("[name='ch']").each(function () {
            this.checked = !this.checked;
        })
    }
    function delAll() {
        var ids = [];
        $("[name='ch']:checked").each(function () {
            ids.push(this.value);
        })
        if (ids.length==0){
            alert("至少选择一个");
        }
        if (confirm("确定要删除吗？")){
            $.post(
                "/delUser",
                {'ids':ids},
                function (mag) {
                    if (mag){
                        alert("删除成功");
                        location.reload();
                    }
                }
            )
        }
    }
</script>
</body>
</html>